package top.kaoshanji.p1ch02c;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

/**
 *
 * author kaoshanji
 * ^_^
 * create time 2025/1/3 15:20
 */
public class MethodHandlesLookupExample02 {

    private static final Logger logger = LogManager.getLogger(MethodHandlesLookupExample02.class);

    public static void main(String[] args) throws Throwable {

        new MethodHandlesLookupExample02().lookupSpecial();

    }

    public MethodHandle lookupSpecial() throws Throwable {
        logger.info("...代码清单 p1ch02c-15：MethodHandles.Lookup#findSpecial方法使用示例...");

        MethodHandles.Lookup lookup = MethodHandles.lookup();
        MethodHandle mh = lookup.findSpecial(MethodHandlesLookupExample02.class, "privateMethod",
                MethodType.methodType(void.class), MethodHandlesLookupExample02.class);

        System.out.println(mh.type());
        mh.invoke(this);
        return mh;
    }


    private void privateMethod() {
        System.out.println("I im is PRIVATE");
    }

}
